<?php

namespace app\store\controller;
use app\store\model\UserInfo as UserInfoModel;
use app\store\model\Job;
use think\Request;
use function ActiveRecord\all;

class UserInfo extends Controller
{
    public $model;
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->model = new UserInfoModel();
    }

    /**
     * 列表
     * @return \think\response\Json
     * @throws \think\exception\DbException
     */
    public function index(){
        $param = $this->request->param();
        $list = $this->model->getList($param);
        return show(self::SUCCESS,'操作成功',$list);
    }

    /**
     * 添加
     * @return array|mixed
     */
    public function add(){
        $data = $this->request->param();
        $result = $this->model->save($data);
        if($result){
            return show(self::SUCCESS,'操作成功');
        }else{
            return show(self::ERROR,'操作失败');
        }
    }

    /**
     * 编辑
     * @param $id
     * @return \think\response\Json
     */
    public function edit($id){
        $data = $this->request->param();
        $result = $this->model->edit($data,$id);
        if($result){
            return show(self::SUCCESS,'操作成功');
        }
        return show(self::ERROR,'操作失败');
    }

    /**
     * 删除
     * @param $id
     * @return \think\response\Json
     * @throws \think\exception\DbException
     */
    public function delete($id){
        $result = UserInfoModel::del($id);
        if($result){
            return show(self::SUCCESS,'操作成功');
        }
        return show(self::ERROR,'操作失败');
    }

    /**
     * 获取岗位列表
     * @return \think\response\Json
     * @throws \think\exception\DbException
     */
    public function jobList(){
        $data = Job::all();
        return show(self::SUCCESS,'操作成功',$data);
    }

    /**
     * 更新用户任务信息
     * @throws \think\db\exception\BindParamException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function updateUser(){
        $result = $this->model->updateTask();exit();
    }
}